home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1998 September / Macworld (1998-09).dmg / Shareware World / Info / For Developers / MacZoop 1.8.3 / More Classes / Advanced Dialogs / ZExtraDialogItems.h < prev   
Text File  |  1998-06-05  |  6KB  |  227 lines

  1. /*************************************************************************************************
  2. *
  3. *
  4. *            MacZoop - "the framework for the rest of us"         
  5. *
  6. *
  7. *
  8. *            ZExtraDialogItems.h    -- some other kinds of dialog item objects
  9. *
  10. *
  11. *            © 1997, Graham Cox
  12. *
  13. *
  14. *
  15. *************************************************************************************************/
  16.  
  17. #pragma once
  18.  
  19. #ifndef __ZEXTRADIALOGITEMS__
  20. #define    __ZEXTRADIALOGITEMS__
  21.  
  22.  
  23. #include    "ZAdvancedDialog.h"
  24.  
  25. // types of lines:
  26.  
  27. typedef enum
  28. {
  29.     plainLine,            
  30.     patternLine,
  31.     raised3DLine,
  32.     etched3DLine
  33. }
  34. LineType;
  35.  
  36. // line class- used to draw straight lines in dialogs
  37.  
  38. class    ZLineDialogItem    : public ZDialogItem
  39. {
  40. protected:
  41.     LineType    itsType;
  42.     short        patIndex;
  43.  
  44. public:
  45.     ZLineDialogItem( ZDialog* aDialog, short item );
  46.     
  47.     virtual void    DrawItem();
  48.     virtual void    InitItem( const long param1, const long param2 );
  49. };
  50.  
  51.  
  52. #define        kLineItemMagicString    'LINE'
  53.  
  54. // icon hiliting style
  55.  
  56. typedef enum
  57. {
  58.     iconHiliteBoldBorder = 1,        // draw bold box around icon
  59.     iconHiliteDarken = 2,            // "select" the icon
  60.     iconHiliteInvertTitle = 4,        // invert the title string
  61.     iconHiliteInvertCell = 8,        // invert the entire cell (but not icon)
  62.     iconHiliteUseHColour = 16,        // use hilite colour for inversion
  63.     iconDefaultHilite = iconHiliteDarken + iconHiliteInvertTitle
  64. }
  65. IconHilite;
  66.  
  67. // n.b. modes can be combined together if desired. Default is darken + invert title
  68.  
  69. // template for icon list box resource ('ICLB')
  70.  
  71. #if PRAGMA_ALIGN_SUPPORTED
  72. #pragma options align=mac68k
  73. #endif
  74.  
  75. // icon types
  76.  
  77. typedef enum
  78. {
  79.     IconPlain    = 128,
  80.     IconColour,
  81.     IconFamily,
  82.     IconSuite,
  83.     IconIndexed
  84. }
  85. IconType;
  86.  
  87. // internal structure kept in list cells:
  88.  
  89. typedef struct
  90. {
  91.     IconType    iType;                // icon's type (colour, family, etc)
  92.     Handle        theIcon;            // handle to the icon if loaded
  93.     short        iconID;                // resource ID of the icon
  94.     long        userData;            // reserved for your own use if needed
  95.     Str31        title;                // icon's title string, if any
  96. }
  97. IconInfo;
  98.  
  99. // icon info in 'ICLB' resource:
  100.  
  101. typedef struct
  102. {
  103.     short        resID;                // res ID of icon
  104.     short        iconType;            // type of icon (n.b. not necessarily same as IconType above)
  105.     short        nameIndex;            // index into STR# for title
  106. }
  107. IconRec;
  108.  
  109. // 'ICLB' structure:
  110.  
  111. typedef struct
  112. {
  113.     short        hiliteStyle;        // hiliting method to use (same as above)
  114.     short        hSpacing;            // spacing between horizontal icons
  115.     short        vSpacing;            // spacing between vertical icons
  116.     short        titleListResID;        // res id of STR# with titles
  117.     Boolean        addTitles : 1;        // show titles with icons
  118.     Boolean        useResName : 1;        // use icon's res name for title
  119.     Boolean        useSmallIcons : 1;    // use small icons instead of large
  120.     Boolean        unused : 5;            // reserved
  121.     short        numIcons;            // number of icons in following array
  122.     IconRec        icons[1];            // variable length array of icon defs
  123. }
  124. IconListBox, *IconListBoxPtr, **IconListBoxHdl;
  125.  
  126. #define        kIconListTemplateResType    'ICLB'
  127. #define        kIconListboxMagicString        'ICLB'
  128.  
  129. // icon types in template
  130.  
  131. #define        kBasicIcon        0        // uses 'ICON' resource
  132. #define        kColourIcon        1        // uses 'cicn' resource
  133. #define        kFamilyIcon        2        // uses 'ICN#', 'icl8', etc. resources
  134.  
  135.  
  136. #if PRAGMA_ALIGN_SUPPORTED
  137. #pragma options align=reset
  138. #endif
  139.  
  140. // icon listbox class- used to create listboxes with icons, based on 'ICLB' resources
  141.  
  142. class    ZIconListBox    : public ZListDialogItem
  143. {
  144. protected:
  145.     Boolean        showTitles;        // show icon titles?
  146.     Boolean        smallIcons;        // TRUE if we use 16 x 16 rather than 32 x 32
  147.     IconHilite    iHilite;        // how to hilite the icons
  148.     
  149.     
  150. public:
  151.     ZIconListBox( ZDialog* aDialog, short item );
  152.     ~ZIconListBox();
  153.  
  154.     virtual void        InitItem( const long param1, const long param2 );
  155.     virtual void        AppendIcon( IconInfo* info );
  156.     virtual void        DrawItem();
  157.     
  158.     inline    IconHilite    GetHiliteStyle() { return iHilite; };
  159.     inline    Boolean        ShowTitles() { return showTitles; };
  160.     
  161. protected:
  162.     virtual void        MakeMacList( const short listTemplateID = 0 );
  163.     virtual void        InstallIconLDEF();
  164.     virtual void        AddIconCells( const short templateID );
  165.     virtual void        DisposeIconCells();
  166. };
  167.  
  168.  
  169. // class for scrolling textbox dialog item:
  170.  
  171. class    ZScrollingTextBox : public ZDialogItem
  172. {
  173. protected:
  174.     TEHandle        te;                    // textEdit record
  175.     ControlHandle    scroll;                // scrollbar
  176.     Boolean            editable;            // TRUE if editable text
  177.     short            resID;                // res ID of TEXT/styl resource
  178.     short            lineHeight;            // height of a line
  179.     short            pageHeight;            // height of a "page"
  180.  
  181. public:
  182.     ZScrollingTextBox( ZDialog* aDialog, short item );
  183.     ~ZScrollingTextBox();
  184.  
  185. // overrides:    
  186.     virtual void        InitItem( const long param1, const long param2 );
  187.     virtual void        DrawItem();
  188.     virtual void        ClickItem( const Point where, const short modifiers );
  189.     virtual void        AdjustCursor( const Point where, const short modifiers );
  190.     virtual void        Activate( const Boolean isActive );
  191.     virtual void        Type( const char theKey, const short modifiers );
  192.     virtual void        Idle();
  193.     virtual void        BecomeHandler( Boolean isBecoming );
  194.     virtual void        Hilite( Boolean state );
  195.     
  196.     virtual void        DoCut();
  197.     virtual void        DoCopy();
  198.     virtual void        DoPaste();
  199.     virtual void        DoClear();
  200.     virtual void        DoSelectAll();
  201.     virtual Boolean        CanPasteType();
  202.     virtual void        UpdateMenus();
  203.     virtual void        HandleCommand( const long theCmd );
  204.     virtual void        HandleCommand( const short menuID, const short itemID );
  205.  
  206. // original methods:    
  207.     virtual void        SetText( Handle textH, Handle styleH = NULL );
  208.     virtual void        GetText( Handle textH, Handle styleH = NULL );
  209.     virtual void        Scroll( short delta );
  210.     virtual void        DoScroll( short partCode );
  211.     
  212.     virtual void        CalScroll();
  213.     
  214.     inline    TEHandle    GetTextEditHandle() { return te; };
  215.     
  216. protected:
  217.     virtual void        MakeMacTEAndScroll();
  218.     virtual void        PreloadText();
  219.     virtual Boolean        PtInScrollbar( const Point mouse );
  220. };
  221.  
  222. // these items provide a vertically scrolling textbox, containing the text from a 'TEXT'
  223. // (and 'styl' if present) resource. The magic string is $$TEXT,id,e where <id> is the res ID
  224. // of the TEXT/styl resources, and <e> is 0 (or missing) for read-only, 1 for editable. If
  225. // editable, the keyboard focus will be applied as normal.
  226.  
  227. #endif